from google.appengine.ext import webapp
#from google.appengine.ext.webapp import util
import datetime
from django.utils import simplejson
#from ft_utils import *
import logging
from ft_table import FtTable
from record import Record
DLZ_PROJECT_LIST = 440872
DLZ_COMPACTION = 478003
FT_USERNAME = 'osu.map@gmail.com'
FT_PASSWORD = 'dlzosumap'
COMPACTION_PROJECT = 423203
class ApptestHandler(webapp.RequestHandler):
    def get(self):
        test = self.request.get('test')
        if test=='ft-table':
            html = 'not implemented yet'
        elif test=='record':
            self.test_record()
        else:
            html = '''
        <a href="/apptest?test=ft-table" target="_blank">Testing FtTable</a>
        '''
        self.response.out.write(html)
    def test_ft_table(self):
        tableid = self.request.get('tableid')
        ft = FtTable(None, None, tableid)
        pass
    def test_record(self, tableid):
        ft = FtTable(None, None, tableid)
        r = Record(ft)
        
def test_record():
    from ft_table import FtTable
    from record import Record
    
    tableid = 478653
    ft = FtTable(None, None, tableid)
    
    #delete all
    ft.delete_all()
    
    for i in range(10):
        r = Record(ft)
        r['Text'] = 'Record %s' % i
        r.insert()
    
    for record in ft.SqlQuery('select rowid from %s' % ft.tableid):
        rowid = record['rowid']
        r = Record(ft, rowid, 437416)
        r['Text'] = '%s - changed by Mel' % r['Text']
        r.update()